<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<% 
	String xm_id=request.getParameter("xm_id")==null?"0":request.getParameter("xm_id");
%>
<html>
	<head>
		<title>工单集合选择</title>
	</head>
	<script type="text/javascript">
		$(function(){

			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$("#material_type_id").combotree({
				url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=0',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			
			$('#table').datagrid({
				title:"工单池",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xm/listGdByXmId?xm_id=<%=xm_id%>',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
					{field:'ck',checkbox:true},
				    {title:'工单id',field:'gd_id',hidden:true},
				    {title:'借款单id',field:'id',hidden:true}

				]],
				columns:[[
					{title:'所属部门',field:'dept_name',width:100,align:'center'},
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:200,align:'center'},
					{title:'借款人',field:'person_name',width:100,align:'center'},
					{title:'日期',field:'operation_date',width:100,align:'center',sort:true},
					{title:'放款日期',field:'actual_operation_date',width:100,align:'center',sort:true},
					{title:'金额',field:'money',width:100,align:'center'},
					{title:'经办人',field:'person_name',width:100,align:'center'},
					{title:'摘要',field:'remark',width:200,align:'center'},
					{title:'操作',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
	                	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEditLoan('"+rowData.id+"');\"/>&nbsp;&nbsp;";

					}}
				]],
				toolbar:
				[
				   {
						id:'add',
						text:'确定',
						iconCls:"icon-save",
						handler:function(){
							doSubmit();
						}
					}
				],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function addOrEditLoan(id){
			openDialogResize("<%=contextPath%>/springViews/gd/viewLoan.jsp?isShow=1&id="+id,800,500);
		}
       function doSubmit(){
    	  var rows=$('#table').datagrid('getSelections');
			var ids="";
			var names="";
			var moneys=0;
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					ids+=rows[i].id+";"+rows[i].money;
					names+="{工单编号:"+rows[i].gd_code+"}{借款人:"+rows[i].person_name+"}{金额:"+rows[i].money+"}";
				}else
				{
					ids+=rows[i].id+";"+rows[i].money+",";
					names+="{工单编号:"+rows[i].gd_code+"}{借款人:"+rows[i].person_name+"}{金额:"+rows[i].money+"},";
					
				}
				moneys+=rows[i].money;
			}
			
			window.opener.rtCallBackRemSet(ids,names,moneys);
			window.close();
       }
		</script>
	<script type="text/javascript">
	</script>
	<body style="height: 97%">
			
		<div id="table" data-options="fit:true,toolbar:'#tb'" ></div>
	</body>
</html>
